package org.example.ThreadLocal;

import com.sun.source.tree.NewArrayTree;

import java.util.concurrent.TimeUnit;

public class ThreadLocal2 {
    private static final ThreadLocal<Person> tl = new ThreadLocal<>();

    public static void main(String[] args) {


        new Thread(() -> {
            try{
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // null
            System.out.println(tl.get());
        }).start();

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            }catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 和当前线程有关 与其他线程无关
            tl.set(new Person());
        }).start();

    }


    public static class Person{
        String name = "zhansan";
    }
}
